package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjWorkBackVisitTemplateField;
import com.zb.entity.ZjWorkBackVisitTemplateFieldContent;
import com.zb.mapper.ZjWorkBackVisitTemplateFieldContentMapper;
import com.zb.service.ZjWorkBackVisitTemplateFieldContentService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 工单回访模板字段内容表，该表存储字段类型为：单选、多选的内容 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-08
 */
@Service
public class ZjWorkBackVisitTemplateFieldContentServiceImpl extends ServiceImpl<ZjWorkBackVisitTemplateFieldContentMapper, ZjWorkBackVisitTemplateFieldContent> implements ZjWorkBackVisitTemplateFieldContentService {

    // 根据回访模板字段ID集合获取字段内容
    @Override
    public List<ZjWorkBackVisitTemplateFieldContent> getByWorkBackVisitTemplateFieldIds(List<Long> workBackVisitTemplateFieldIds) {
        if (null == workBackVisitTemplateFieldIds || workBackVisitTemplateFieldIds.isEmpty()) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjWorkBackVisitTemplateFieldContent> wrapper = new QueryWrapper<>();
        wrapper.select("id", "work_back_visit_template_field_id", "val");
        wrapper.in("work_back_visit_template_field_id", workBackVisitTemplateFieldIds);
        return this.list(wrapper);
    }

    // 根据回访模板字段ID集合删除字段内容
    @Override
    public void deleteBatchByWorkBackVisitTemplateFieldIds(List<Long> workBackVisitTemplateFieldIds) {
        if (null == workBackVisitTemplateFieldIds || workBackVisitTemplateFieldIds.isEmpty()) {
            return;
        }
        QueryWrapper<ZjWorkBackVisitTemplateFieldContent> wrapper = new QueryWrapper<>();
        wrapper.in("work_back_visit_template_field_id", workBackVisitTemplateFieldIds);
        this.remove(wrapper);
    }

    @Override
    public List<ZjWorkBackVisitTemplateFieldContent> getByWorkBackVisitTemplateFieldId(Long workBackVisitTemplateFieldId) {
        List<Long> workBackVisitTemplateFieldIds = new ArrayList<>();
        workBackVisitTemplateFieldIds.add(workBackVisitTemplateFieldId);
        return getByWorkBackVisitTemplateFieldIds(workBackVisitTemplateFieldIds);
    }

    // 根据自定义字段ID删除
    @Override
    public void removeByWorkBackVisitTemplateFieldIds(List<Long> workBackVisitTemplateFieldIds) {
        if (CollectionUtils.isEmpty(workBackVisitTemplateFieldIds)) {
            return;
        }
        QueryWrapper<ZjWorkBackVisitTemplateFieldContent> wrapper = new QueryWrapper<>();
        wrapper.in("work_back_visit_template_field_id", workBackVisitTemplateFieldIds);
        this.remove(wrapper);
    }
}
